home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Graphics⁄Sound / crit / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-24  |  3.7 KB  |  139 lines  |  [TEXT/????]

  1. /*
  2.  * event.c - the main event loop
  3.  */
  4.  
  5. #include <quickdraw.h>
  6. #include <memory.h>
  7. #include <window.h>
  8. #include <dialog.h>
  9. #include <menu.h>
  10. #include <event.h>
  11. #include <desk.h>
  12. #include <control.h>
  13. #include <packages.h>
  14. #include <toolutil.h>
  15. #include <syserr.h>
  16.  
  17. #include "critic.h"
  18.  
  19. /*
  20.  * doevent() - one loop through the main event handler
  21.  *   Returns 1 if the user wants to continue; 0 if it's time to quit
  22.  */
  23.  
  24. int
  25. doevent()
  26. {
  27.     GrafPtr saveport;
  28.     EventRecord myevent;
  29.     char whichchar;        /* the char that was typed        */
  30.     WindowPtr whichwindow;    /* Points to window of MouseDown    */
  31.     WindowPtr activewindow;    /* Points to the frontmost window    */
  32.     DialogPtr whichdialog;    /* dialog of MouseDown            */
  33.     short whichitem;        /* mouse's dialog item            */
  34.     long menucommand;        /* a menu command to do (menu + item)    */
  35.     int windowcode;        /* What mouse was in when event posted. */
  36.     ControlHandle whichcontrol; /* the control that was pressed        */
  37.     short partcode;        /* the pressed part of that control    */
  38.     Point pt;            /* temp point                */
  39.     int userdone;        /* True when user wants to exit program    */
  40.     Point dlgorig;        /* topLeft of movable dialogs        */
  41.  
  42.     userdone = 0;
  43.     SystemTask();        /* give the system a moment of time    */
  44.  
  45.     /*
  46.      * see which window is currently selected
  47.      * (for non-mouse events),
  48.      * Then grab an event and interpret it.
  49.      */
  50.  
  51.     GetPort(&activewindow);
  52.  
  53.     if (!GetNextEvent(everyEvent, &myevent)) {
  54.     draw_idle();
  55.     } else if ((myevent.modifiers & cmdKey) &&
  56.       (myevent.what == keyDown || myevent.what == autoKey)) {
  57.  
  58.     /*
  59.      * It's a command-key keystroke.
  60.      * (command keystrokes are handled here since dialogs can't)
  61.      */
  62.  
  63.     whichchar = (char) (myevent.message & charCodeMask);
  64.     markmenus(activewindow);
  65.     menucommand = MenuKey(whichchar);
  66.     userdone = docommand(menucommand);
  67.     } else if (IsDialogEvent(&myevent)) {
  68.         /* here's where we'd handle modeless dialog events */
  69.     } else {
  70.     switch (myevent.what) {
  71.     case keyDown: 
  72.     case autoKey:
  73.         criticize();
  74.         break;
  75.     case updateEvt:        /* update the appropriate window */
  76.         if ((WindowPtr)(myevent.message) == windoc) {
  77.         redoc();
  78.         }
  79.         break;
  80.     case activateEvt:        /* activate or deactivate window */
  81.         if (myevent.modifiers & 1) {
  82.             SetPort((WindowPtr) myevent.message);
  83.         } else {
  84.             SetPort(screenport);
  85.         }
  86.         break;
  87.     case diskEvt:            /* disk inserted - eject or init it */
  88.         if (HiWord(myevent.message) != noErr) {
  89.         dlgorig.h = 90; dlgorig.v = 100;
  90.         (void) DIBadMount(pass(dlgorig), myevent.message);
  91.         }
  92.         break;
  93.     case mouseDown:            /* a mouse click someplace    */
  94.  
  95.         windowcode = FindWindow(pass(myevent.where), &whichwindow);
  96.         switch (windowcode) {
  97.         case inSysWindow:            /* a DA's window */
  98.         SystemClick(&myevent, whichwindow);
  99.         break;
  100.         case inMenuBar:            /* a menu item */
  101.         markmenus(activewindow);
  102.         menucommand = MenuSelect(pass(myevent.where));
  103.         userdone = docommand(menucommand);
  104.         break;
  105.         case inGoAway:            /* Close box    */
  106.         if (TrackGoAway(whichwindow, pass(myevent.where))) {
  107.             if (whichwindow == windoc) {
  108.             userdone = 1;
  109.             }
  110.         }
  111.         break;
  112.         case inZoomIn:
  113.         case inZoomOut:            /* Zoom box    */
  114.         case inGrow:            /* Grow Region */
  115.         case inDrag:            /* Title Bar */
  116.         case inContent:            /* Somewhere in the window */
  117.         if (whichwindow != FrontWindow()) {
  118.             /* the window isn't active - just activate it */
  119.             SelectWindow(whichwindow);
  120.         } else {
  121.  
  122.             /*
  123.              * The window is active,
  124.              *   interpret the mouse-down in this window's context.
  125.              */
  126.  
  127.             GlobalToLocal(&myevent.where);
  128.             if (whichwindow == windoc) {    /* it's our window */
  129.                 criticize();
  130.             }
  131.         }
  132.         break;
  133.         }
  134.         break;
  135.     }
  136.     }
  137.     return(!userdone);
  138. }
  139.